<include file="Public/header" /> 

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4>会员文章列表</h4>
		<div class="bs-example-bg-classes">
			<p class="bg-warning">
			说明：会员抓取文章插入广告并且发布的文章；默认无需审核保存即可发布，开启审核有利于预防客户插入违反广告文章等。如需开启或关闭<a href="<{:U('Admin/Option/siteOpt',array('k'=>6))}>">点击这里</a>
			</p>
		</div>
		<div class="bk10"></div>
		<div>
			<form class="form-inline">
				<div class="form-group form-group-sm">
					<label for="title">标题：</label>
					<input type="text" class="form-control" id="title" name="title" placeholder="标题" value="<{$title}>">
				</div>
				<div class="form-group form-group-sm">
					<label for="start_time">创建时间：</label>
					<input type="text" class="form-control laydate-icon" id="start_time" name="start_time" onclick="laydate({istime:true, format:'YYYY-MM-DD hh:mm:ss'})" value="<{$start_time?($start_time|date='Y-m-d H:i:s',###):''}>">
					<span>-</span>
					<input type="text" class="form-control laydate-icon" id="end_time" name="end_time" onclick="laydate({istime:true, format:'YYYY-MM-DD hh:mm:ss'})" value="<{$end_time?($end_time|date='Y-m-d H:i:s',###):''}>">
				</div>
				<div class="form-group form-group-sm">
					<label for="sort">排序：</label>
					<select class="form-control" name="sort" id="sort">
						<foreach name="sortList" item="row">
							<option value="<{$key}>" <if condition="$key eq $sort">selected="selected"</if> ><{$row['name']}></option>
						</foreach>
					</select>
				</div>
				<div class="bk10"></div>
				<?php /* Todo: 多表查询 或者 先异步查询用户得到ID再加入查询
				<div class="form-group form-group-sm">
					<label for="member_name">会员昵称：</label>
					<input type="text" class="form-control" id="member_name" name="member_name" placeholder="会员昵称" value="<{$member_name}>">
					<label for="member_phone">手机号码：</label>
					<input type="text" class="form-control" id="member_phone" name="member_phone" placeholder="手机号码" value="<{$member_phone}>">
				</div>
				<div class="bk10"></div>
				*/ ?>
				<div class="form-group form-group-sm">
					<label>文章审核状态：</label>
					<div class="checkbox">
						<label class="checkbox-inline">
							<input type="checkbox" id="stateWaitCheck" <if condition='$stateWait'>checked=checked</if> >
							<input type="hidden" name="stateWait" id="stateWait" value="<{$stateWait}>">
							<span style="color:#FFA530">待审核</span>
						</label>
						<label class="checkbox-inline">
							<input type="checkbox" id="statePassCheck" <if condition='$statePass'>checked=checked</if> >
							<input type="hidden" name="statePass" id="statePass" value="<{$statePass}>">
							<font color="green">已通过</font>
						</label>
						<label class="checkbox-inline">
							<input type="checkbox" id="stateVetoCheck" <if condition='$stateVeto'>checked=checked</if> >
							<input type="hidden" name="stateVeto" id="stateVeto" value="<{$stateVeto}>">
							<font color="red">被否决</font>
						</label>
					</div>
				</div>
				<button type="submit" class="btn btn-default btn-sm col-md-offset-1"><b>文章筛选</b></button>
			</form>
		</div>
		<div class="bk10"></div>
		<div class="btn-toolbar">
			<div class="btn-group btn-group-sm">
				<button type="button" id="sBtnAll" class="btn btn-default">全选</button>
				<button type="button" id="sBtnBut" class="btn btn-default">反选</button>
				<button type="button" id="sBtnNull" class="btn btn-default">不选</button>
			</div>
			<div class="btn-group btn-group-sm">
				<button type="button" onclick="selectPass()" class="btn btn-default">审核通过</button>
				<button type="button" onclick="selectVeto()" class="btn btn-default">审核否决</button>
				<button type="button" onclick="selectDel()" class="btn btn-default">删除</button>
			</div>
		</div>
		<table class="table table-bordered table-hover">
			<tr>
				<th><input type="checkbox" name="selectAll" id="selectAll"></th>
				<th>编号</th>
				<th>标题</th>
				<th>创建时间</th>
				<th>创建人</th>
				<th>状态</th>
				<th>操作</th>
			</tr>

			<empty name="list">
				<tr><td colspan="6" style="text-align:center;color:#999">～暂无数据～</td></tr>
			<else /> 

				<foreach name="list" item="vo">
					<tr>
						<td><input type="checkbox" name="batchId" class="batchId" value="<{$vo['id']}>" data-status="<{$vo['status']}>" ></td>
						<td><{$vo['id']}></td>
						<td><{$vo['title']}></td>
						<td><{$vo['createtime']|date="Y-m-d H:i",###}></td>
						<td onclick="layer.tips('手机号码：<{$vo['mobile']}>',this,{tips:[1, '#3595CC']});">
							<{$vo['username']}> 
						</td>
						<td>
							<if condition="$vo['status'] eq 0">
								待审核
							<elseif condition="$vo['status'] eq 1"/>
								<font color="green">已通过</font>
							<elseif condition="$vo['status'] eq -2"/>
								<font color="red">被否决</font>
							</if>
						</td>
						<td>
							<a href="<{:U('Admin/Article/articleEdit',array('id'=>$vo['id'],'k'=>2,'sk'=>1,'p'=>I('p')))}>">审核文章</a>
							<a href="javascript:void(0)" class="delAct" data-id="<{$vo['id']}>">删除</a>
						</td>
					</tr>
				</foreach>
			
			</empty>
			
		</table>
		
		<div class="pagebar">
			<{$pager}>
		</div>
		
	</div>
	<!-- mainCon// -->
	
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
$(function(){

	checkAllState();

	$(".delAct").click(function(){
		var that = this;
		layer.confirm('您是否确认删除该记录？删除后不可恢复！', {icon: 3, title:'提示'}, function(index){
			var itemid = $(that).attr("data-id");
			$.post("<{:U('Admin/Article/articleDel')}>",{id:itemid},function(r){
				if(r.error == 1){
					layer.close(index);
					layer.alert(r.errmsg,{icon: 2});
				}else{
					window.location.reload();
				}
			});
		});
		return false;
	});

	$('#stateWaitCheck').click(function() {
		if ($(this).prop('checked')) {
			$('#stateWait').val('1');
		} else {
			$('#stateWait').val('0');
		}
	});
	$('#statePassCheck').click(function() {
		if ($(this).prop('checked')) {
			$('#statePass').val('1');
		} else {
			$('#statePass').val('0');
		}
	});
	$('#stateVetoCheck').click(function() {
		if ($(this).prop('checked')) {
			$('#stateVeto').val('1');
		} else {
			$('#stateVeto').val('0');
		}
	});

	$('#sBtnAll').click(function() {
		$('.batchId').prop('checked', true);
		$('#selectAll').prop('checked', true);
	});

	$('#sBtnNull').click(function() {
		$('.batchId').prop('checked', false);
		$('#selectAll').prop('checked', false);
	});

	$('#sBtnBut').click(function() {
		$('.batchId').each(function(index, el) {
			if ($(this).prop('checked'))
			{
				$(this).prop('checked', false);
			}
			else
			{
				$(this).prop('checked', true);
			}
		});
		checkAllState();
	});

	$('.batchId').change(function() {
		checkAllState();
	});

	$('#selectAll').click(function() {
		$('.batchId').prop('checked', true);
		$('#selectAll').prop('checked', true);
	});
});

// 检查全选状态
function checkAllState()
{
	var allFalg = true;
	$('.batchId').each(function(index, el) {
		if ($(this).prop('checked') === false)
		{
			allFalg = false;
		}
	});
	if (allFalg)
	{
		$('#selectAll').prop('checked', true);
	}
	else
	{
		$('#selectAll').prop('checked', false);
	}
}

// 批量通过选择项
function selectPass()
{
	var idArray = new Array;
	var subCount = 0;
	var subWait = 0;
	var subPass = 0;
	var subVeto = 0;
	$('.batchId').each(function(index, el) {
		if ($(this).prop('checked')) {
			// alert($(this).attr('data-status'));
			subCount++;
			switch ($(this).attr('data-status'))
			{
				case '0':
					subWait++;
					break;
				case '1':
					subPass++;
					break;
				case '-2':
					subVeto++;
					break;
			}
			idArray[index] = $(this).val();
		};
	});
	var tipsMsg = '您确定审核<font color="red">通过</font>所选的 '+subCount+' 篇文章？<br>其中：<br>待审核：'+subWait+'<br><font color="green">已通过</font>：'+subPass+'<br><font color="red">被否决</font>：'+subVeto+'<br>[请谨慎操作]';
	if (subCount) {
		layer.confirm(tipsMsg,{title:'请确定'},function(){
			$.post('<{:U('Admin/Article/articleBatchPass')}>', {batchId: idArray}, function(data) {
				if (data.error) {
					layer.msg(data.errmsg,{icon:2});
				} else {
					layer.msg(data.errmsg,{icon:1,time:1000},function(){
						// window.location.href = "__SELF__";
						window.location.reload();
					});
				}
			});
		});
	} else {
		layer.msg('请选择要操作的项目',{icon:0});
	}
}
// 批量否决选择项
function selectVeto()
{
	var idArray = new Array;
	var subCount = 0;
	var subWait = 0;
	var subPass = 0;
	var subVeto = 0;
	$('.batchId').each(function(index, el) {
		if ($(this).prop('checked')) {
			// alert($(this).attr('data-status'));
			subCount++;
			switch ($(this).attr('data-status'))
			{
				case '0':
					subWait++;
					break;
				case '1':
					subPass++;
					break;
				case '-2':
					subVeto++;
					break;
			}
			idArray[index] = $(this).val();
		};
	});
	var tipsMsg = '您确定审核<font color="red">否决</font>所选的 '+subCount+' 篇文章？<br>其中：<br>待审核：'+subWait+'<br><font color="green">已通过</font>：'+subPass+'<br><font color="red">被否决</font>：'+subVeto+'<br>[请谨慎操作]';
	if (subCount) {
		layer.confirm(tipsMsg,{title:'请确定'},function(){
			$.post('<{:U('Admin/Article/articleBatchVeto')}>', {batchId: idArray}, function(data) {
				if (data.error) {
					layer.msg(data.errmsg,{icon:2});
				} else {
					layer.msg(data.errmsg,{icon:1,time:1000},function(){
						// window.location.href = "__SELF__";
						window.location.reload();
					});
				}
			});
		});
	} else {
		layer.msg('请选择要操作的项目',{icon:0});
	}
}
// 批量删除选择项
function selectDel()
{
	var idArray = new Array;
	var subCount = 0;
	var subWait = 0;
	var subPass = 0;
	var subVeto = 0;
	$('.batchId').each(function(index, el) {
		if ($(this).prop('checked')) {
			// alert($(this).attr('data-status'));
			subCount++;
			switch ($(this).attr('data-status'))
			{
				case '0':
					subWait++;
					break;
				case '1':
					subPass++;
					break;
				case '-2':
					subVeto++;
					break;
			}
			idArray[index] = $(this).val();
		};
	});
	var tipsMsg = '您确定审核<font color="red">删除</font>所选的 '+subCount+' 篇文章？<br>其中：<br>待审核：'+subWait+'<br><font color="green">已通过</font>：'+subPass+'<br><font color="red">被否决</font>：'+subVeto+'<br>[请谨慎操作]';
	if (subCount) {
		layer.confirm(tipsMsg,{title:'请确定'},function(){
			$.post('<{:U('Admin/Article/articleBatchDel')}>', {batchId: idArray}, function(data) {
				if (data.error) {
					layer.msg(data.errmsg,{icon:2});
				} else {
					layer.msg(data.errmsg,{icon:1,time:1000},function(){
						// window.location.href = "__SELF__";
						window.location.reload();
					});
				}
			});
		});
	} else {
		layer.msg('请选择要操作的项目',{icon:0});
	}
}
</script>

<include file="Public/footer" /> 